package com.beehoo.dcportal.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.dao.ICommonDao;
import com.beehoo.dcportal.model.MenuBean;
import com.beehoo.dcportal.model.PortletBean;
import com.beehoo.dcportal.model.StreetBean;
import com.beehoo.dcportal.model.ThemeBean;
import com.beehoo.dcportal.service.ICommonServ;
import com.beehoo.dcportal.utils.CommonUtils;

public class CommonServImpl implements ICommonServ {
	private ICommonDao commDao;
	
	public void setCommDao(ICommonDao commDao) {
		this.commDao = commDao;
	}
	
	@Override
	public List<MenuBean> queryNavMenu(String streetId) throws BaseException {
		return commDao.queryNavMenu(streetId);
	}
	
	@Override
	public List<PortletBean> queryPortlets(String streetId, String themeId)
			throws BaseException {
		return commDao.queryPortlets(streetId, themeId);
	}

	@Override
	public ThemeBean queryTheme(String streetId) throws BaseException {
		return commDao.queryTheme(streetId);
	}

	@Override
	public StreetBean queryStreet(String streetDomain) throws BaseException {
		return commDao.queryStreet(streetDomain);
	}

	@Override
	public void validateIDCardNum(String idCardNum) throws BaseException {
		if(CommonUtils.nvlToString(idCardNum).equals("")){
			throw new BaseException("custom.messages.error.idcard.num.empty");
		}
		boolean ret = false;
		String id = null;
		id = commDao.queryResidentIdByIDCard(idCardNum);
		if(CommonUtils.nvlToString(id).equals("")){
			id = commDao.queryWorderIdByIDCard(idCardNum);
			if(!CommonUtils.nvlToString(id).equals("")){
				ret = true;
			}
		}else{
			ret = true;
		}
		if(!ret){
			throw new BaseException("custom.messages.error.idcard.num.none");
		}
	}

	@Override
	public List<MenuBean> querySpecialMenu(String streetId,
			String parentMenuSpecial) throws BaseException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("streetId", streetId);
		paramMap.put("parentMenuSpecial", parentMenuSpecial);
		return commDao.querySpecialMenu(paramMap);
	}
}
